/*
 * 文件名：ColumnTypeEnum.java
 * 版权：亚信联创版权所有
 * 描述：TODO
 * 修改人：napo
 * 修改时间：2014-11-17
 * 修改内容：TODO
 */
package com.ailk.bigdata.etl.realstream.server.model;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.ailk.bigdata.etl.realstream.server.service.FormatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.ByteFormatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.DateTimeFormatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.IPFormatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.IntFormatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.NULLFormatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.ShortFormatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.StringFormatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.UnsignedByteFromatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.UnsignedIntFromatHandler;
import com.ailk.bigdata.etl.realstream.server.service.impl.UnsignedShortFromatHandler;

/**
 * @description TODO
 * @author [xuwei3]
 * @version [版本号,2014-11-17]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public enum ColumnTypeEnum
{
	DATATIME("^datetime=(\\d+)\\[(\\D*)\\]$", DateTimeFormatHandler.class), UNSIGNEDBYTE("^unsignedbyte=(\\d+)$", UnsignedByteFromatHandler.class), UNSIGNEDSHORT(
			"^unsignedshort=(\\d+)$", UnsignedShortFromatHandler.class), UNSIGNEDINT("^unsignedint=(\\d+)$", UnsignedIntFromatHandler.class), STRING(
			"^string=(-?\\d+)$", StringFormatHandler.class), INT("^int=(\\d+)$", IntFormatHandler.class), SHORT("^short=(\\d+)",
			ShortFormatHandler.class), BYTE("^byte=(\\d+)$", ByteFormatHandler.class), IP("^ip=(\\d+)\\[(\\d)\\]$", IPFormatHandler.class), NULL(
			"^null=(\\d+)$", NULLFormatHandler.class);

	private String pattern;// 规则
	private Class<? extends FormatHandler> handler;// 方法名

	private ColumnTypeEnum(String pattern, Class<? extends FormatHandler> handler)
	{
		this.pattern = pattern;
		this.handler = handler;
	}

	public String getPattern()
	{
		return pattern;
	}

	public Class<? extends FormatHandler> getHandler()
	{
		return handler;
	}

	public void setHandler(Class<? extends FormatHandler> handler)
	{
		this.handler = handler;
	}

	public void setPattern(String pattern)
	{
		this.pattern = pattern;
	}

	public static void main(String[] args)
	{
		System.out.println(System.currentTimeMillis());
		System.out.println("datetime=8[yyyyMMddHHmmss]".matches("^datetime=(\\d+)\\[(\\D*)\\]$"));
		Pattern patt1 = Pattern.compile("^datetime=(\\d+)\\[(\\D*)\\]$");
		Matcher match1 = patt1.matcher("datetime=8[yyyyMMddHHmmss]");
		System.out.println(match1.matches());
		System.out.println(match1.group(1));
		System.out.println(match1.group(2));

		System.out.println("unsignedbyte=4{16=[unsignedByte=1;unsignedByte=1;unsignedByte=1;unsignedByte=1;byte=2;byte=2;byte=4;byte=4]}"
				.matches("^unsignedbyte=(\\d+)\\{(\\d+)=\\[([\\w;=]+)\\]\\}$"));
		Pattern patt = Pattern.compile("^unsignedbyte=(\\d+)\\{(\\d+)=\\[([\\w;=]+)\\]\\}$");
		Matcher match = patt.matcher("unsignedbyte=4{16=[unsignedByte=1;unsignedByte=1;unsignedByte=1;unsignedByte=1;byte=2;byte=2;byte=4;byte=4]}");
		System.out.println(match.matches());
		System.out.println(match.group(1));
		System.out.println(match.group(2));
		System.out.println(match.group(3));
	}

}
